package com.book.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.book.entity.Book;
import com.book.service.ManagerService;

/**
 * Servlet implementation class ManagerAddBook
 */
@WebServlet("/ManagerAddBook")
public class ManagerAddBook extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ManagerAddBook() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取添加页面的请求参数，然后调用业务逻辑层对象，实现最终修改
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		String book_id = request.getParameter("book_id");
		String book_name =request.getParameter("book_name");
		String author =request.getParameter("author");
		String press = request.getParameter("press");
		
		
		Book b=new Book(book_id, book_name, author, press);
		ManagerService ms=new ManagerService();
		boolean result=ms.addBook(b);
		System.out.println(b);
		System.out.println(result);
		if(result){
			request.getRequestDispatcher("ManagerSelectBook").forward(request, response);
		}else{
			response.sendRedirect("add.jsp");
		}
		
	}

	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
